home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / networking / pgpuam / sources / pgpuammsgformat.c < prev    next >
Encoding:
Text File  |  2000-06-23  |  5.6 KB  |  182 lines

  1. /*
  2.     File:            PGPUAMmsgFormat.h
  3.  
  4.     Description:    
  5.  
  6.     Written by:    Vinnie Moscaritolo
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.     You may incorporate this sample code into your applications without
  13.     restriction, though the sample code has been provided "AS IS" and the
  14.     responsibility for its operation is 100% yours.  However, what you are
  15.     not permitted to do is to redistribute the source as "DSC Sample Code"
  16.     after having made changes. If you're going to re-distribute the source,
  17.     we require that you make it clear in the source that the code was
  18.     descended from Apple Sample Code, but that you've made changes.
  19. */
  20.  
  21. //------------------------------------------------------------------------------------
  22. #pragma mark Includes
  23. //------------------------------------------------------------------------------------
  24. #include <String.h>
  25. #include "AFPPackets.h"
  26. #include "ClientUAM.h" 
  27.  
  28. #include "machdepnetmacros.h"
  29. #include "PGPUAMmsgFormat.h"
  30. #include "PGPUAMclientProtocol.h"
  31.  
  32. // ---------------------------------------------------------------------------
  33. #pragma mark Local Prototypes
  34. // ---------------------------------------------------------------------------
  35.  
  36. static void*  FormatLoginContCmdHdr    (const void    *outbuf    );
  37.  
  38.  
  39. #pragma mark -
  40. #pragma mark PGPUAM Login Command 
  41. // ---------------------------------------------------------------------------
  42. void*  FormatLoginCmd( const void       *outbuf, 
  43.                             StringPtr     serverVersion, 
  44.                             StringPtr     uamName, 
  45.                             StringPtr     userName,
  46.                             StringPtr    challengeString    )
  47. // ---------------------------------------------------------------------------
  48. {
  49.     UByte1 *msgP  = (UByte1*) outbuf;
  50.  
  51.     MOVE_TO_NET_1        (msgP,     kFPLogin    )
  52.     PLstrcpy((StringPtr) msgP,    serverVersion);          msgP += serverVersion[0]+1;
  53.      PLstrcpy((StringPtr) msgP,     uamName);                msgP += uamName[0]+1;
  54.     PLstrcpy((StringPtr) msgP,     userName);                msgP += userName[0]+1;
  55.     PLstrcpy((StringPtr) msgP,     challengeString);        msgP += challengeString[0]+1;
  56.     
  57.      return (msgP);
  58. }
  59.  
  60.  
  61. // ---------------------------------------------------------------------------
  62. void*  ParseLoginCmd(const void *inbuf,  UInt32 *length, PUAM_LOGIN_CMD *vmsgP)
  63. // ---------------------------------------------------------------------------
  64. {
  65.     UByte1    *msgP  = (UByte1*)inbuf;
  66.  
  67.     vmsgP->userName = msgP; 
  68.     SKIP_FROM_NET        (msgP,     vmsgP->userName[0] + 1    );
  69.  
  70.     vmsgP->challengeString = msgP; 
  71.     SKIP_FROM_NET        (msgP,     vmsgP->challengeString[0] + 1    );
  72.     
  73.      *length -= (UByte1*)inbuf - msgP;
  74.      return (msgP);
  75. }
  76.  
  77.  
  78. // ---------------------------------------------------------------------------
  79. void*  FormatChallengeStr( const void   *outbuf, 
  80.                             UInt8          *challengeBuffer,
  81.                             UInt32          challengeBufferSize )
  82. // ---------------------------------------------------------------------------
  83. {
  84.     UByte1 *msgP  = (UByte1*) outbuf;
  85.  
  86.     MOVE_TO_NET_1        (msgP,    challengeBufferSize    )
  87.     if(challengeBufferSize > 0)
  88.         {
  89.         MOVE_TO_NET_BLOCK    (msgP,    challengeBuffer, challengeBufferSize);
  90.         }
  91.     return (msgP);
  92. }
  93.  
  94.  
  95.  
  96. #pragma mark - 
  97. #pragma mark PGPUAM Login Response
  98.  
  99. // ---------------------------------------------------------------------------
  100. void*  FormatLoginResp( const     void       *outbuf, 
  101.                                 StringPtr    counterChallengePString, 
  102.                                  StringPtr    fingerPrintPString  )
  103. // ---------------------------------------------------------------------------
  104. {
  105.     UByte1 *msgP  = (UByte1*) outbuf;
  106.  
  107.     PLstrcpy((StringPtr) msgP,     counterChallengePString);    msgP += counterChallengePString[0]+1;
  108.     PLstrcpy((StringPtr) msgP,     fingerPrintPString);        msgP += fingerPrintPString[0]+1;
  109.       return (msgP);
  110. }
  111.  
  112.  
  113.  
  114. // ---------------------------------------------------------------------------
  115. void*  ParseLoginResp(const void *inbuf,  UInt32 *length, PUAM_LOGIN_RESP *vmsgP)
  116. // ---------------------------------------------------------------------------
  117. {
  118.     UByte1    *msgP  = (UByte1*)inbuf;
  119.  
  120.     vmsgP->CounterChallengePString = msgP; 
  121.     SKIP_FROM_NET        (msgP,     vmsgP->CounterChallengePString[0] + 1    );
  122.  
  123.     vmsgP->FingerPrintPString = msgP; 
  124.     SKIP_FROM_NET        (msgP,     vmsgP->FingerPrintPString[0] + 1    );
  125.     
  126.      *length -= (UByte1*)inbuf - msgP;
  127.      return (msgP);
  128. }
  129.  
  130. #pragma mark -
  131.  
  132. #pragma mark PGPUAM Login Continue Command Header
  133. // ---------------------------------------------------------------------------
  134. void*  FormatLoginContCmdHdr( const     void     *outbuf)
  135. // ---------------------------------------------------------------------------
  136. {
  137.     UByte1 *msgP  = (UByte1*) outbuf;
  138.  
  139.     MOVE_TO_NET_1        (msgP,     kFPLoginCont    )
  140.     MOVE_TO_NET_1        (msgP,     0    )
  141.  
  142. // Alternate UAMs require that the client use a ID number of 1 when 
  143. // performing a LoginContinue Packet, this is a hardcoded value..
  144. // I suspect this is a server bug!!
  145.      SWAP_TO_NET_2        (msgP,     1    )
  146.  
  147. // this is a bug for now.. the sever requires at least 8 bytes of foo.
  148. //     SKIP_TO_NET_8        (msgP);
  149.      
  150.      return (msgP);
  151. }
  152.  
  153. // ---------------------------------------------------------------------------
  154. void*  FormatLoginContinueCmd( const     void       *outbuf, 
  155.                                 StringPtr    counterChallengePString )
  156. // ---------------------------------------------------------------------------
  157. {
  158.     UByte1 *msgP  = (UByte1*) outbuf;
  159.  
  160.     msgP = (UInt8*) FormatLoginContCmdHdr(msgP);
  161.      PLstrcpy((StringPtr) msgP,     counterChallengePString);    msgP += counterChallengePString[0]+1;
  162.       return (msgP);
  163. }
  164.  
  165.  
  166. // ---------------------------------------------------------------------------
  167. void*  ParseLoginContinueCmd(const void *inbuf,  UInt32 *length, PUAM_LOGIN_CONT_CMD *vmsgP)
  168. // ---------------------------------------------------------------------------
  169. {
  170.     UByte1    *msgP  = (UByte1*)inbuf;
  171.  
  172.     vmsgP->SigPString = msgP; 
  173.     SKIP_FROM_NET        (msgP,     vmsgP->SigPString[0] + 1    );
  174.  
  175.       *length -= (UByte1*)inbuf - msgP;
  176.      return (msgP);
  177. }
  178.  
  179.  
  180.  
  181.  
  182.